package com.traffic.trafficCar;

import com.traffic.entity.TrafficCar;
import com.traffic.repository.trafficcar.TrafficCarRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TrafficCarServiceImpl implements TrafficCarService {
@Autowired
private TrafficCarRepository repository;
	@Override
	@Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
	public void addTraffic(TrafficCar trafficCar) {
		repository.save(trafficCar);
	}

	@Override
	@Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
	public void updateTraffic(TrafficCar trafficCar) {
		repository.save(trafficCar);
	}

	@Override
	@Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
	public void delTraffic(Long id) {
		repository.delete(Long.valueOf(id));
	}

	@Override
	public Page<TrafficCar> findTrafficCar(Pageable page) {
		return repository.findAll(page);
	}

	@Override
	public Page<TrafficCar> findAllByLineOrCar(String line, String car, Pageable page) {
		return repository.findAllByLineOrCar(line,car,page);
	}

	@Override
	public TrafficCar get(Long id) {
		return repository.findById(id);
	}
}
